﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mail;
using EmailReporting;
using EmailReporting.Data;

namespace EmailRuntime
{
    class Program
    {
        // Author: Otto Neff | webapps-in-action.com 
        static void Main(string[] args)
        {
            Invoicing invoice = new Invoicing();
            MemoryStream pdfFile = invoice.CreatePdfInvoice(new Invoice
            {
                InvoiceCustomer = "HelloWorldCustomer",
                InvoiceDate = DateTime.Now,
                InvoicePositions = new List<InvoicePos>{ 
                    new InvoicePos { Amount = 10, UnitPrice = (decimal)2.65, Description = "Product A"},              
                    new InvoicePos { Amount = 7, UnitPrice = (decimal)1.50, Description = "Product B"},                
                    new InvoicePos { Amount = 2, UnitPrice = (decimal)43.00, Description = "Product C"},                
                }
            });
            Attachment attachment = new Attachment(pdfFile, "YourInvoice.pdf");
            MailMessage msg = new MailMessage("test@test.me", "test@test.me", "Your Invoice", "Please see your Invoice as PDF attached.");
            msg.Attachments.Add(attachment);
            SmtpClient client = new SmtpClient("127.0.0.1", 25);
            client.Credentials = new System.Net.NetworkCredential("test@test.me", "test");
            client.Send(msg);
        }
    }
}